package logic

import (
	"context"
	"house/models"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseInfoLogic {
	return &HouseInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源详情
func (l *HouseInfoLogic) HouseInfo(in *house.HouseInfoReq) (*house.HouseInfoResp, error) {
	// todo: 房源详情
	var err error
	var h models.House
	err = h.Find(int(in.Id))
	if err != nil {
		logx.Error("房源详情展示失败")
		return nil, err
	}

	return &house.HouseInfoResp{
		City:    h.City,
		Address: h.Address,
		Floor:   h.Floor,
		Size:    float32(h.Size),
		Price:   int64(h.Price),
		Info:    h.Info,
		Status:  int64(h.Status),
		UserId:  int64(h.UserId),
	}, nil
}
